package com.hotelsystem.reservations.layouts;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.hotelsystem.reservations.rooms.RoomTypesEnum;

public class CreateRoomView {
	private JLabel roomNumber;
	private JLabel roomType;
	private JLabel smokersType;
	private JLabel imagePath;
	private JTextField roomNumberText;
	private JRadioButton smokers, noSmokers;
	private ButtonGroup smokersGroup;
	private JFileChooser imageFilePath;
	private JPanel mainPanel;
	private JButton fileChooseButton;
	private JButton saveButton;

	private JComboBox<String> roomTypeBox;

	// private int roomNumber;
	// private RoomTypesEnum roomType;
	// private boolean isSmokersFree;
	// private String imageFilePath;

	public CreateRoomView() {
		buildUI();
	}

	private void buildUI() {
		mainPanel = new JPanel(new BorderLayout());
		JPanel centerPanel = new JPanel();
		GridLayout layout = new GridLayout();
		centerPanel.setLayout(layout);
		centerPanel.setBorder(BorderFactory.createEmptyBorder(60, 60, 60, 60));
		layout.setColumns(2);
		layout.setRows(0);
		layout.setHgap(100);
		layout.setVgap(100);

		roomNumber = new JLabel("Please add number of room:");
		centerPanel.add(roomNumber);
		roomNumberText = new JTextField();
		centerPanel.add(roomNumberText);
		roomType = new JLabel("Choose room type:");
		centerPanel.add(roomType);
		roomTypeBox = new JComboBox<String>();
		roomTypeBox.addItem(RoomTypesEnum.ONE_PERSON_ROOM.getName());
		roomTypeBox.addItem(RoomTypesEnum.TWO_PERSONS_ROOM.getName());
		roomTypeBox.addItem(RoomTypesEnum.SUITE.getName());
		roomTypeBox.addItem(RoomTypesEnum.LUXE_SUITE.getName());
		roomTypeBox.addItem(RoomTypesEnum.PRESIDENTIAL_SUITE.getName());
		centerPanel.add(roomTypeBox);
		smokersType = new JLabel("Is it for smookers?");
		centerPanel.add(smokersType);
		smokersGroup = new ButtonGroup();
		smokers = new JRadioButton("Yes");
		noSmokers = new JRadioButton("No");
		smokersGroup.add(smokers);
		smokersGroup.add(noSmokers);
		JPanel radioButtonsPanel = new JPanel();
		BoxLayout radioButtonLayout = new BoxLayout(radioButtonsPanel,
				BoxLayout.X_AXIS);
		radioButtonsPanel.setLayout(radioButtonLayout);
		radioButtonsPanel.add(smokers);
		radioButtonsPanel.add(noSmokers);
		centerPanel.add(radioButtonsPanel);
		imagePath = new JLabel("Choose image for room:");
		centerPanel.add(imagePath);
		fileChooseButton = new JButton("Choose");

		centerPanel.add(fileChooseButton);

		JPanel buttonsPanel = new JPanel();
		FlowLayout buttonsLayout = new FlowLayout(FlowLayout.CENTER);
		buttonsPanel.setLayout(buttonsLayout);
		saveButton = new JButton("Save");
		buttonsPanel.add(saveButton);
		mainPanel.add(buttonsPanel, BorderLayout.SOUTH);

		mainPanel.add(centerPanel, BorderLayout.CENTER);
	}

	public void addListenerForChoose(ActionListener action) {
		fileChooseButton.addActionListener(action);
	}

	public JComboBox<String> getRoomTypeBox() {
		return roomTypeBox;
	}

	public void addListenerForSave(ActionListener action) {
		saveButton.addActionListener(action);
	}

	public JLabel getRoomNumber() {
		return roomNumber;
	}

	public JTextField getRoomNumberText() {
		return roomNumberText;
	}

	public JRadioButton getSmokers() {
		return smokers;
	}

	public JRadioButton getNoSmokers() {
		return noSmokers;
	}

	public ButtonGroup getSmokersGroup() {
		return smokersGroup;
	}

	public JFileChooser getImageFilePath() {
		return imageFilePath;
	}

	public JPanel getMainPanel() {
		return mainPanel;
	}

	// public static void main(String[] args) {
	// CreateRoomView room = new CreateRoomView();
	//
	// JFrame frame = new JFrame();
	// // frame.setJMenuBar(mainMenu.getMainMenuBar());
	// frame.add(room.getMainPanel());
	// frame.setSize(500, 600);
	// frame.setTitle("Hotel System");
	// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	// frame.setVisible(true);
	// }

}
